home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / languages / assembly / powervisor_113.lzh / Source / GetCode.c < prev    next >
C/C++ Source or Header  |  1991-09-15  |  2KB  |  95 lines

  1. /* Routine to get the code for a named key
  2.     Works best in AmigaDOS 2.0
  3.     In AmigaDOS 1.3 only special keys (like 'enter', 'esc', 'up', ...) work
  4.  
  5. Compile with :
  6.     lc -v -cmsw -O GetCode
  7.     blink GetCode.o to GetCode lib pv:pvdevelop/lib/PVCallStub.lib
  8. */
  9.  
  10.  
  11.  
  12. #include <exec/types.h>
  13. #include "pv:PVDevelop/include/PV/pvcallroutines.h"
  14. #include <pragmas/exec.h>
  15. #include <pragmas/keymap.h>
  16. #include <string.h>
  17.  
  18. APTR PVCallTable;
  19.  
  20. struct myCode
  21.     {
  22.         char *str;
  23.         UWORD code;
  24.     };
  25.  
  26. struct myCode Codes[] =
  27.     {
  28.         "f1",            0x50,
  29.         "f2",            0x51,
  30.         "f3",            0x52,
  31.         "f4",            0x53,
  32.         "f5",            0x54,
  33.         "f6",            0x55,
  34.         "f7",            0x56,
  35.         "f8",            0x57,
  36.         "f9",            0x58,
  37.         "f10",        0x59,
  38.         "esc",        0x45,
  39.         "enter",    0x43,
  40.         "ret",        0x44,
  41.         "up",            0x4c,
  42.         "down",        0x4d,
  43.         "right",    0x4e,
  44.         "left",        0x4f,
  45.         "del",        0x46,
  46.         "help",        0x5f,
  47.         "tab",        0x42,
  48.         "numl",        0x5a,
  49.         "scrl",        0x5b,
  50.         "prtsc",    0x5d,
  51.         "home",        0x3d,
  52.         "end",        0x1d,
  53.         "nup",        0x3e,
  54.         "nleft",    0x2d,
  55.         "nright",    0x2f,
  56.         "ndown",    0x1e,
  57.         "pgup",        0x3f,
  58.         "pgdn",        0x1f,
  59.         "ins",        0x0f,
  60.         "ndel",        0x3c,
  61.         NULL,            0
  62.     };
  63.  
  64.  
  65. int __saveds __asm Code (register __a0 char *cmdline, register __a2 APTR table[])
  66. {
  67.     struct Library *KeymapBase;
  68.     char codequal[3],*p;
  69.     struct myCode *mc;
  70.  
  71.     PVCallTable = table;
  72.  
  73.     p = PVCParseString (cmdline);
  74.  
  75.     mc = Codes;
  76.     while (mc->str)
  77.         {
  78.             if (!strcmp (mc->str,p))
  79.                 {
  80.                     return ((int)(mc->code));
  81.                     break;
  82.                 }
  83.             mc++;
  84.         }
  85.  
  86.     KeymapBase = (struct Library *)OpenLibrary ("keymap.library",0);
  87.     if (KeymapBase)
  88.         {
  89.             MapANSI (p,1,codequal,1,NULL);
  90.             CloseLibrary (KeymapBase);
  91.             return ((int)codequal[0]);
  92.         }
  93.     else return (0);
  94. }
  95.